package suse.hotel.admin.admin.Controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javafx.beans.DefaultProperty;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import suse.hotel.admin.admin.DTO.AdminDTO;
import suse.hotel.admin.admin.DTO.UserDTO;
import suse.hotel.admin.admin.Entity.Admin;
import suse.hotel.admin.admin.Mapper.AdminMapper;
import suse.hotel.admin.admin.Service.UserService;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    AdminMapper adminMapper;
    @Autowired
    UserService userService;

    @RequestMapping("/adminLogin")
    @ResponseBody
    public String login(Admin admin, HttpSession session) {
        AdminDTO adminDTO=adminMapper.loginSelect(admin);
        if (adminDTO!=null) {
            session.setAttribute("user",adminDTO);
            return "true";
        }
        else
            return "false";
    }

    @RequestMapping("/seluser")
    @ResponseBody
    public String selUsers(@RequestParam(defaultValue="1") int page,@RequestParam(defaultValue="10") int limit) {
        return userService.selUsers(page,limit);
    }

    @RequestMapping("/delMenber")
    @ResponseBody
    public String delMenber(int id){
        if(adminMapper.delMenber(id)!=0)
            return "true";
        return "false";
    }
}
